<!--
*
* Copyright 2015 HISP Tanzania
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*
* @since 2015
* @author Joseph Chingalo profschingalo@gmail.com>
*
*
-->
<ion-header>

  <ion-navbar [color]="(colorSettings$ |async).colorAttributes.main">
    <ion-title>
      <span [translate]="'Data entry form'"></span>
    </ion-title>
  </ion-navbar>
</ion-header>


<ion-content>
  <ion-grid>
    <ion-row>
      <ion-col>
        <div *ngIf="entryFormParameter" class="item-card" full padding-bottom padding-top>
          <div (tap)="goBack()">
            <b>
              <span [translate]="'Organisation unit'"></span>
            </b> : {{ entryFormParameter.orgUnit.name }}
            <br>
            <b>
              <span [translate]="'Form'"></span>
            </b> : {{ entryFormParameter.dataSet.name }}
            <br>
            <b>
              <span [translate]="'Period'"></span>
            </b> : {{ entryFormParameter.period.name }}
            <br>
            <span *ngIf="!isLoading">
              <b>
                <span [translate]="'Synced'"></span>
              </b> : {{ storageStatus.online }}
              <b>
                <span [translate]="'Not synced'"></span>
              </b> : {{storageStatus.offline }}</span>
          </div>
          <aggregate-conflict-handler (conflictFoundAction)="scrollEntryFormUp()" (mergeDataAction)="onMergingWithOnlineData($event)"
            (dataSetCompletenessInfoAction)="onDataSetCompletenessInformattionLoaded($event)" [(dataValuesObject)]="dataValuesObject"
            [orgUnitId]="entryFormParameter.orgUnit.id" [dataSetId]="entryFormParameter.dataSet.id" [period]="entryFormParameter.period.iso"
            [dataDimension]="this.entryFormParameter.dataDimension"></aggregate-conflict-handler>
          <div *ngIf="!isLoading && indicators && indicators.length > 0">
            <div (click)="viewEntryFormIndicators(indicators)" class="item-card" color="font-color">
              <ion-item>
                <span [translate]="'Available indicators'"></span>
                <ion-badge color="icon-color" item-end>{{ indicators.length }}</ion-badge>
              </ion-item>
            </div>
          </div>
        </div>
        <div *ngIf="isLoading">
          <loading [loadingMessage]="loadingMessage" [loadingSize]="'large'"></loading>
        </div>
        <div *ngIf="!isLoading">
          <div *ngIf="entryFormType && entryFormType == 'CUSTOM'">
            <custom-data-entry-form [dataEntryFormDesign]="dataEntryFormDesign" (onCustomFormInputChange)="updateData($event)"
              (onUpdateDataSetCompleteness)="updateDataSetCompleteness()" (onViewUserCompletenessInformation)="viewUserCompletenessInformation($event)"
              [data]="dataValuesObject" [entryFormType]="'aggregate'" [entryFormSections]="entryFormSections"
              [dataUpdateStatus]="dataUpdateStatus" [isDataSetCompleted]="isDataSetCompleted"
              [isDataSetCompletenessProcessRunning]="isDataSetCompletenessProcessRunning" [dataSetsCompletenessInfo]="dataSetsCompletenessInfo"></custom-data-entry-form>
          </div>
          <div *ngIf="entryFormType && entryFormType != 'CUSTOM'">
            <div *ngIf="entryFormSections && entryFormSections.length == 0">
              <empty-list-notification [emptyListMessage]="translationMapper['The is no field associated with this entry form, Please contact our help desk'] "></empty-list-notification>
            </div>
            <default-data-entry-form (onPaginationChange)="changePagination($event)" (onUpdateDataSetCompleteness)="updateDataSetCompleteness()"
              (onViewUserCompletenessInformation)="viewUserCompletenessInformation($event)" (onChange)="updateData($event)"
              (onSectionListOpen)="openSectionList()" [entryFormType]="entryFormType"
              [isDataSetCompletenessProcessRunning]="isDataSetCompletenessProcessRunning" [currentUser]="currentUser"
              [icons]="icons" [isDataSetCompleted]="isDataSetCompleted" [dataSetsCompletenessInfo]="dataSetsCompletenessInfo"
              [dataValuesSavingStatusClass]="dataValuesSavingStatusClass" [dataValuesObject]="dataValuesObject" [pager]="pager"
              [entryFormSections]="entryFormSections"></default-data-entry-form>
          </div>
        </div>
      </ion-col>
    </ion-row>
  </ion-grid>



</ion-content>
